home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BasicComboBoxRenderer.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  112 lines

  1. /*
  2.  * @(#)BasicComboBoxRenderer.java    1.6 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.plaf.basic;
  21.  
  22. import com.sun.java.swing.*;
  23. import com.sun.java.swing.event.*;
  24. import com.sun.java.swing.border.*;
  25.  
  26. import java.awt.Component;
  27. import java.awt.Color;
  28.  
  29. import java.io.Serializable;
  30.  
  31.  
  32. /**
  33.  * ComboBox renderer
  34.  * <p>
  35.  * Warning: serialized objects of this class will not be compatible with
  36.  * future swing releases.  The current serialization support is appropriate 
  37.  * for short term storage or RMI between Swing1.0 applications.  It will
  38.  * not be possible to load serialized Swing1.0 objects with future releases
  39.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  40.  * baseline for the serialized form of Swing objects.
  41.  *
  42.  * @version 1.6 02/02/98
  43.  * @author Arnaud Weber
  44.  */
  45. public class BasicComboBoxRenderer extends JLabel
  46.     implements ListCellRenderer, Serializable
  47. {
  48.     protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
  49.  
  50.     public BasicComboBoxRenderer() {
  51.     super();
  52.     setOpaque(true);
  53.     setBorder(noFocusBorder);
  54.     }
  55.  
  56.  
  57.     public Component getListCellRendererComponent(
  58.         JList list, 
  59.     Object value,
  60.         int index, 
  61.         boolean isSelected, 
  62.         boolean cellHasFocus)
  63.     {
  64.     
  65.     /**if (isSelected) {
  66.         setBackground(UIManager.getColor("ComboBox.selectedBackground"));
  67.         setForeground(UIManager.getColor("ComboBox.selectedForeground"));
  68.     } else {
  69.         setBackground(UIManager.getColor("ComboBox.background"));
  70.         setForeground(UIManager.getColor("ComboBox.foreground"));
  71.     }**/
  72.  
  73.         if(isSelected) {
  74.             setBackground(list.getSelectionBackground());
  75.             setForeground(list.getSelectionForeground());
  76.         } else {
  77.             setBackground(list.getBackground());
  78.             setForeground(list.getForeground());
  79.         }
  80.     
  81.         setFont(list.getFont());
  82.  
  83.     if (value instanceof Icon) {
  84.         setIcon((Icon)value);
  85.     } else {
  86.         setText((value == null) ? "" : value.toString());
  87.     }
  88.     return this;
  89.     }
  90.  
  91.  
  92.     /**
  93.      * A subclass of BasicComboBoxRenderer that implements UIResource.
  94.      * BasicComboBoxRenderer doesn't implement UIResource
  95.      * directly so that applications can safely override the
  96.      * cellRenderer property with BasicListCellRenderer subclasses.
  97.      * <p>
  98.      * Warning: serialized objects of this class will not be compatible with
  99.      * future swing releases.  The current serialization support is appropriate
  100.      * for short term storage or RMI between Swing1.0 applications.  It will
  101.      * not be possible to load serialized Swing1.0 objects with future releases
  102.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  103.      * baseline for the serialized form of Swing objects.
  104.      */
  105.     public static class UIResource extends BasicComboBoxRenderer
  106.         implements com.sun.java.swing.plaf.UIResource
  107.     {
  108.     }
  109. }
  110.  
  111.  
  112.